import './public-path'
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';


if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.error(err));


declare global {
  interface Window {
    microApp: any
    __MICRO_APP_NAME__: string
    __MICRO_APP_ENVIRONMENT__: string
  }
}

let app: any = null;
async function mount () {
  app = await platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .catch(err => console.error(err))
}

function unmount () {
  app.destroy();
  app = null;
  console.log('微应用child-angular卸载了');
}


if (!window.__MICRO_APP_ENVIRONMENT__) {
  (window as any)[`micro-app-${window.__MICRO_APP_NAME__}`] = { mount, unmount }
} else {
  mount();
}